package com.person.ntv.service.sys.impl;

import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.person.common.PageParams;
import com.person.exception.ServiceException;
import com.person.ntv.dao.sys.SysCodesetMapper;
import com.person.ntv.entity.sys.SysCode;
import com.person.ntv.entity.sys.SysCodeset;
import com.person.ntv.service.base.impl.BaseServiceImpl;
import com.person.ntv.service.sys.CommonService;
import com.person.ntv.service.sys.SysCodeService;
import com.person.ntv.service.sys.SysCodeSetService;
@Service("sysCodeSetService")
public class SysCodeSetServiceImpl extends BaseServiceImpl<SysCodeset> implements SysCodeSetService{
	@Autowired
   private SysCodesetMapper sysCodesetMapper;
	@Autowired
   private CommonService commonService;
	@Autowired
   private SysCodeService sysCodeService;
   @Autowired
   public void setBaseMapper(){
	   super.setBaseMapper(this.sysCodesetMapper);
   }

@Override
public int deleteByPrimaryKeys(BigDecimal[] ids) {
	try{
		int result=0;
	    for(BigDecimal id:ids){
	    	result+=deleteByPrimaryKey(id);
	    	//删除字典值
	    	SysCode sc=new SysCode();
	    	sc.setCsId(id);
	    	sysCodeService.delete(sc);
	    }
	    return result;
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  }
}

@Override
public int validateCsName(String csName, String id) throws ServiceException {
	try{
	    return commonService.validateOne("sys_codeset","cn_name",csName, id);
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  } 
}

@Override
public int validateCsCode(String csCode, String id) throws ServiceException {
	try{
	    return commonService.validateOne("sys_codeset","en_name",csCode, id);
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  } 
}

@Override
public Page<SysCodeset> getCodeSetPage(PageParams params)
		throws ServiceException {
	try{
		PageHelper.startPage(params.getPage(),params.getRows(),params.getOrderStr(null));
		return sysCodesetMapper.selectPage(params.getParams());
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  } 
}
   
}
